#include <vector>

#include "libnoscript.hpp"

using noscript::Cmd;
using noscript::CxxEnv;
using noscript::CxxTarget;
using noscript::ERR_OK;
using noscript::Error;
using noscript::Path;

#define TRY NOSCRIPT_TRY

static Error runtime(int argc, char** argv)
{
    TRY(noscript::RebuildNoScript(argc, argv));
    TRY(noscript::GetCxxCmd().Arg("--version").Run());

    CxxEnv env;

    env.build_type = CxxEnv::RELEASE;
    env.target_link_type = CxxEnv::SHARED;

    TRY(PkgConfig(&env, "opencv4"));

    CxxTarget main(&env, "main", CxxTarget::EXECUTABLE, CxxEnv::AUTO_LINK);
    main.Src(Path() / "main.cpp");

    NOSCRIPT_TRY(main.Build());

    NOSCRIPT_TRY(
        Cmd(main.GetTargetPath())
            .ArgPath(Path({ "..", "data", "image.jpg" }))
            .Run());

    NOSCRIPT_LOG(INFO, "done");
    return ERR_OK;
}

int main(int argc, char** argv)
{
    Error err = runtime(argc, argv);

    if (err != ERR_OK) {
        return 1;
    }
    return 0;
}
